using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using GeYiHome.PublicLibrary;

namespace GeYiHome.OpenApi.Filter
{
    public class ExceptionFilter: FilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            var result = new NlResult<object>(null)
            {
                Code = "",
                Msg = filterContext.Exception.Message
            };
            if (filterContext.Exception.GetType() != typeof(OpenApiException<>))
                result.Result = false;
            filterContext.Result = new JsonResult()
            {
                Data = result,
                ContentType = "application/json",
                ContentEncoding = Encoding.UTF8,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
    }
}